refactor: PipelineBuilder LIFO to FIFO for intuitive middleware ordering - #438
Merged
JusterZhu merged 2 commits intoMay 26, 2026
Merged
Conversation
…ImmutableQueue) The LIFO stack caused middleware execution order to be the reverse of registration order, which was the root cause of the MacStrategy pipeline bug fixed in GeneralLibrary#436. With FIFO (ImmutableQueue), registration order now equals execution order for intuitive API semantics. - PipelineBuilder: ImmutableStack → ImmutableQueue, Push → Enqueue - All OS strategies: register Hash → Compress → Patch (executes in same order) - MacStrategy: also changed to UseMiddlewareIf<PatchMiddleware> for consistency Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors PipelineBuilder to execute middleware in FIFO (registration) order by switching from ImmutableStack to ImmutableQueue, and updates platform strategies so registration order matches intended execution order (Hash → Compress → Patch).
Changes:
- Refactor
PipelineBuilderstorage from stack (LIFO) to queue (FIFO) so middleware executes in registration order. - Reorder Windows/Linux middleware registration to
HashMiddleware→CompressMiddleware→PatchMiddleware(conditional). - Make MacStrategy’s patch middleware conditional via
UseMiddlewareIfto match other platforms.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/c#/GeneralUpdate.Core/Pipeline/PipelineBuilder.cs | Switch middleware collection to FIFO queue and iterate in registration order. |
| src/c#/GeneralUpdate.Core/Strategy/WindowsStrategy.cs | Reorder middleware registration to match FIFO execution semantics. |
| src/c#/GeneralUpdate.Core/Strategy/LinuxStrategy.cs | Reorder middleware registration to match FIFO execution semantics. |
| src/c#/GeneralUpdate.Core/Strategy/MacStrategy.cs | Make Patch middleware conditional and align registration order with other platforms. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
12
to
+15
| /// <summary> | ||
| /// LIFO��Last In First Out. | ||
| /// LIFO£¬Last In First Out. | ||
| /// </summary> | ||
| private ImmutableStack<IMiddleware> _middlewareStack = ImmutableStack<IMiddleware>.Empty; | ||
| private ImmutableQueue<IMiddleware> _middlewareQueue = ImmutableQueue<IMiddleware>.Empty; |
| foreach (var middleware in _middlewareStack) | ||
| foreach (var middleware in _middlewareQueue) | ||
| { | ||
| await middleware.InvokeAsync(context); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Follow-up to #436. Change
PipelineBuilderfromImmutableStack(LIFO) toImmutableQueue(FIFO) so that middleware registration order equals execution order.Motivation
The LIFO stack caused the MacStrategy pipeline bug (fixed in #436) — registration order
UseMiddleware<A>().UseMiddleware<B>()executes B before A, which is counterintuitive. With FIFO, the code says what it does.Changes
Pipeline/PipelineBuilder.csImmutableStack→ImmutableQueue,Push→EnqueueStrategy/WindowsStrategy.csStrategy/LinuxStrategy.csStrategy/MacStrategy.csUseMiddleware→UseMiddlewareIffor consistencyAll three platforms now register in the same order:
Test plan
🤖 Generated with Claude Code